package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
//@RequestMapping("/api/order")
@RequestMapping("/admin/order")
@Tag(name = "订单管理接口", description = "订单管理相关业务接口")
public class OrderController {
    @Autowired
    private OrderService service;

    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("查询订单详情：{}",id);
        OrderVO orderVO=service.details(id);
        return Result.success(orderVO);
    }

    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(
            String number, String beginTime, String endTime,String phone,
            Integer status,Integer page, Integer pageSize
    ){
        log.info("订单搜索，订单号：{}，下单时间：{}~{},订单状态：{}，页码：{}，页大小：{}",
                number,beginTime,endTime,status,page,pageSize);
       PageResult pageResult=service.conditionSearch(
                number,beginTime,endTime,phone,status,page,pageSize);
        return Result.success(pageResult);
    }

    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO orderCancelDTO){
        log.info("订单取消：{}",orderCancelDTO);
        service.cancel(orderCancelDTO);
        return Result.success();
    }

    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO=service.statistics();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id){
        service.complete(id);
        return Result.success();
    }

    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO orderRejectionDTO){
        log.info("订单拒绝：{}",orderRejectionDTO);
        service.rejection(orderRejectionDTO);
        return Result.success();
    }

    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("订单确认：{}",ordersConfirmDTO.getId());
        service.confirm(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("订单派送:{}",id);
        service.delivery(id);
        return Result.success();
    }
}
